package sample
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.setup.MockMvcBuilders

import spock.lang.Specification

import com.sample.controller.SampleController
import com.sample.service.SampleService


class SampleSpock extends Specification {

	MockMvc mockMvc;
	SampleService  mockService;

	def setup() {
		def controller = new SampleController();
		mockService = Mock(SampleService.class);
		controller.service = mockService;
		mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
	}

	def "스팍과 스프링 MVC 테스트 연동 테스트"() {
		when:
		def response = mockMvc.perform(get("/sample").accept(MediaType.APPLICATION_JSON).characterEncoding("UTF-8"));

		then:
		response
			.andExpect(status().isOk())
			.andDo(print());

//		response.andReturn().response.contentAsString == "hello spock";
	}
}
